var canvasContainer = document.getElementById("canvasContainer");
//var canvas = document.createElement('canvas');
//canvas.style.position = "absolute";
//canvasContainer.appendChild(canvas);
var canvas = document.getElementById("canvas");
var cxt = canvas.getContext("2d");

function getWidth(element) { return Math.max(element.scrollWidth, element.offsetWidth, element.clientWidth); }

function getHeight(element) { return Math.max(element.scrollHeight, element.offsetHeight, element.clientHeight); }

var cvMinWidth = 300;
var cvMinHeight = 300;
var cvMaxWidth = 950;
var cvMaxHeight = 772;

var canvasLeft;
var canvasTop;

var windowResetHandler = function() {
	w = getWidth(canvasContainer);
	h = getHeight(canvasContainer);

	if(w >= cvMaxWidth) {
		canvas.width = cvMaxWidth;
	} else {
		canvas.width = w;
	}
	if(h >= cvMaxHeight) {
		canvas.height = cvMaxHeight;
	} else {
		canvas.height = h;
	}
	canvasLeft = (w / 2 - (canvas.width / 2));
	canvas.style.marginLeft = canvasLeft + "px";
	canvasTop = (h / 2 - (canvas.height / 2));
	canvas.style.marginTop = canvasTop + "px";
}
windowResetHandler();
//window.onresize = windowResetHandler;
var Time = 91;
var timer;

var completeNum = 2;
var whichUI = 1; //确定界面
var roundDefaultUI = 1;
var roundOneStartUI = 2;
var roundOneUI = 3
var roundOneCompleteUI = 4;
var roundTwoStartUI = 5;
var roundTwoUI = 6;
var roundTwoCompleteUI = 7;
var roundThreeStartUI = 8;
var roundThreeUI = 9;
var roundThreeCompleteUI = 10;
var roundEndUI = 20;
var restartUInum = 0;
var rightNum = 0; //标记正确盒子的坐标
var badNum = [0]; //标记错误盒子
var userSelected = 0; //标记用户选择
var isSelectError = false; //标记选择错误
var isSelectRight = false; //标记选择正确
var roundNum = 0; //回合数
var boxArray = [
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0]
]; // 第一组数据仅占位，盒子目的坐标
var boxSpeed = [0, 0, 0, 0, 0, 0, 0]; //每个盒子的速度
var boxArrayDefault = [
	[0, 0],
	[0, -360],
	[0, -360],
	[0, -360],
	[0, -360],
	[0, -360],
	[0, -360]
]; // 第一组数据仅占位，盒子初始坐标
var bottomBoxArray = [
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
];
var roundNextSign = false;
var updateBoxComplete = false;
var rightWord = ["", "自由", "平等", "公正", "法治", "爱国", "敬业", "诚信", "友善", "富强", "民主", "文明", "和谐"];
var wordEnglishArray = ["", "Freedom", "Equality", "Justice", "Rule of  Law", "Patriotism", "Dedication", "Integrity", "Friendship", "Prosperity", "Democracy", "Civility", "Harmony"]
var badWord = [
	["", "", "", "", "", ""],
	["", "自在", "自强", "自主", "自我", "随意"],
	["", "博爱", "关心", "平常", "关爱", "仁义"],
	["", "公平", "公理", "正义", "真理", "公民"],
	["", "法律", "法制", "德治", "宪法", "人治"],
	["", "爱党", "爱社会主义", "爱家", "爱自己", "忠诚"],
	["", "廉洁", "奋斗", "爱岗", "勇敢", "干一行爱一行"],
	["", "诚实", "孝顺", "承诺", "信任", "智慧"],
	["", "温和", "善良", "恭敬", "俭朴", "谦让"],
	["", "强盛", "伟大", "复兴", "富裕", "富庶"],
	["", "民治", "民享", "民有", "人民", "民生"],
	["", "文化", "教化", "明理", "生态", "文雅"],
	["", "和美", "协调", "绿色", "可持续", "和平"]
]
var mouseX = 0;
var mouseY = 0;
var mouseXCorrection = 0;
var mouseYCorrection = 0;

var start = {
	x: ((canvas.width / 2) + 150),
	y: (canvas.height / 2),
	w: 150,
	h: 45
}
var startTwo = {
	x: ((canvas.width / 2) + 150),
	y: ((canvas.height / 2) + canvas.height * 0.1),
	w: 150,
	h: 45
}
var startThree = {
	x: ((canvas.width / 2) + 150),
	y: ((canvas.height / 2) + canvas.height * 0.1 + canvas.height * 0.1),
	w: 150,
	h: 45
}

var Box = {
	x: 0,
	y: 0,
	w: 130,
	h: 88,
	speed: 1
}
var roundWarmingBox = {
	w: 350,
	h: 200,
	x: (canvas.width / 2 - 350 / 2),
	y: (canvas.height / 2 - 200 / 2),
	text: "",
	btX: (canvas.width / 2 - 350 / 2),
	btY: (canvas.height / 2 - 200 / 2) + 200 * 0.8,
	text2: "",
	bt2X: (canvas.width / 2 - 350 / 2) + 350 * 0.5,
	bt2Y: (canvas.height / 2 - 200 / 2) + 200 * 0.8,
	text3: "",
}
var updateBox = function() {
	if(whichUI == roundOneUI) {
		if(roundNextSign == true) {
			var x = 0;
			var y = 0;
			var bottomX = 0;
			var bottomY = 0;
			var speedX = 0;
			var speedY = 0;
			for(var i = 1; i <= 6; i++) {
				if(i == rightNum && isSelectRight == true) { //正确盒子移至正确位置
					x = boxArrayDefault[i][0];
					y = boxArrayDefault[i][1];
					bottomX = bottomBoxArray[roundNum][0];
					bottomY = bottomBoxArray[roundNum][1];
					speedX = toDecimal((bottomX - boxArray[i][0]) / (4800 / 60));
					speedY = toDecimal((bottomY - boxArray[i][1]) / (4800 / 60));
					if(speedX > 0) { //确定往左移还是往右移,无意义
						if(x < bottomX) {
							x = x + speedX;
							x = toDecimal(x);
							boxArrayDefault[i][0] = x;
						}
					} else {
						if(x > bottomX) {
							x = x + speedX;
							x = toDecimal(x);
							boxArrayDefault[i][0] = x;
						}
					}

					if(y < bottomY) {
						y = y + speedY;
						boxArrayDefault[i][1] = y;
					}
				} else { //错误盒子右移
					x = boxArrayDefault[i][0];
					var speed = toDecimal(((canvas.width + 110) - boxArray[i][0]) / (4800 / 60));
					if(x < canvas.width + 110) {
						x = x + speed;
						boxArrayDefault[i][0] = x;
					}
				}
			}
		} else {
			var y = 0;
			var yDefault = 0;
			var speed = 0;
			for(var i = 1; i <= 6; i++) {
				y = boxArray[i][1];
				yDefault = boxArrayDefault[i][1];

				y = toDecimal(y);
				yDefault = toDecimal(yDefault);

				speed = boxSpeed[i];

				if(yDefault < y) {
					yDefault = yDefault + speed;
					yDefault = toDecimal(yDefault);
					boxArrayDefault[i][1] = toDecimal(yDefault);
					updateBoxComplete = false;
				}else{
					updateBoxComplete = true;
				}
			}
		}

	}
}
canvas.addEventListener("click",
	function(e) {
		if(whichUI == roundDefaultUI) {
			if(e.clientX >= start.x + canvasLeft &&
				e.clientX <= start.x + start.w + canvasLeft &&
				e.clientY >= start.y + canvasTop &&
				e.clientY <= start.y + start.h + canvasTop) { //开启第一关
				whichUI = roundOneStartUI;
				roundNum = 1;
				setTimeout("updateUINum()", 2000);

				assignNum();
				main();

				initTimer();
			}
			if(e.clientX >= startTwo.x + canvasLeft &&
				e.clientX <= startTwo.x + startTwo.w + canvasLeft &&
				e.clientY >= startTwo.y + canvasTop &&
				e.clientY <= startTwo.y + startTwo.h + canvasTop) { //开启第二关
				whichUI = roundTwoStartUI;
				setTimeout("updateUINum()", 2000);
				main();

				initTimer();
			}
			if(e.clientX >= startThree.x + canvasLeft &&
				e.clientX <= startThree.x + startThree.w + canvasLeft &&
				e.clientY >= startThree.y + canvasTop &&
				e.clientY <= startThree.y + startThree.h + canvasTop) { //开启第三关
				whichUI = roundThreeStartUI;
				setTimeout("updateUINum()", 2000);
				main();

				initTimer();
			}
		} else if(whichUI == roundOneCompleteUI || whichUI == roundTwoCompleteUI) {
			if(whichUI == roundOneCompleteUI) {
				//进入下一关（第二关）
				if(e.clientX >= roundWarmingBox.btX + canvasLeft &&
					e.clientX < roundWarmingBox.bt2X + canvasLeft &&
					e.clientY >= roundWarmingBox.btY + canvasTop &&
					e.clientY < roundWarmingBox.h + roundWarmingBox.y + canvasTop) {
					whichUI = roundTwoStartUI;
					setTimeout("updateUINum()", 2000);

					initTimer();
				}
				//返回主菜单
				if(e.clientX >= roundWarmingBox.bt2X + canvasLeft &&
					e.clientX < roundWarmingBox.w * 0.5 + roundWarmingBox.bt2X + canvasLeft &&
					e.clientY >= roundWarmingBox.btY + canvasTop &&
					e.clientY < roundWarmingBox.h + roundWarmingBox.y + canvasTop) {
					whichUI = roundDefaultUI;
				}
			}
			if(whichUI == roundTwoCompleteUI) {
				//进入下一关（第三关）
				if(e.clientX >= roundWarmingBox.btX + canvasLeft &&
					e.clientX < roundWarmingBox.bt2X + canvasLeft &&
					e.clientY >= roundWarmingBox.btY + canvasTop &&
					e.clientY < roundWarmingBox.h + roundWarmingBox.y + canvasTop) {
					whichUI = roundThreeStartUI;
					setTimeout("updateUINum()", 2000);

					initTimer();
				}
				//返回主菜单
				if(e.clientX >= roundWarmingBox.bt2X + canvasLeft &&
					e.clientX < roundWarmingBox.w * 0.5 + roundWarmingBox.bt2X + canvasLeft &&
					e.clientY >= roundWarmingBox.btY + canvasTop &&
					e.clientY < roundWarmingBox.h + roundWarmingBox.y + canvasTop) {
					setTimeout(whichUI = roundDefaultUI, 2000);
				}
			}
		} else if(whichUI == roundOneUI) {
			userSelected = whichbox(e.clientX - canvasLeft, e.clientY - canvasTop);
			if(userSelected != null && roundNextSign == false && updateBoxComplete == true) {
				if(userSelected == rightNum) {
					isSelectRight = true;
					roundNextSign = true;
					setTimeout("roundNext()", 2500);
				} else if(userSelected == null) {
					//alert("未选择任何盒子")
				} else {
					isSelectError = true;
					setTimeout("roundReset()", 2500);
				}
				//alert(whichbox(e.clientX, e.clientY))
			}

		} else if(whichUI == roundTwoUI) {
			var s = rtWhichBox(e.clientX - canvasLeft, e.clientY - canvasTop);
			if(s != null && rtSelectRightSign == false) {
				if(roundTwoSelectOne == 0) {
					roundTwoSelectOne = s;
				} else {
					if(s != roundTwoSelectOne) {
						roundTwoSelectTwo = s;
						rtIsSelectRight();
					}
				}
			}

		} else if(whichUI == roundEndUI) {
			//重新开始本关
			if(e.clientX >= roundWarmingBox.btX + canvasLeft &&
				e.clientX < roundWarmingBox.bt2X + canvasLeft &&
				e.clientY >= roundWarmingBox.btY + canvasTop &&
				e.clientY < roundWarmingBox.h + roundWarmingBox.y + canvasTop) {
					console.log(restartUInum)
					if(restartUInum == roundOneUI){
						whichUI = roundOneStartUI;
						roundReset();
					}
					if(restartUInum == roundTwoUI){
						whichUI = roundTwoStartUI;
						setRoundTwoDefault();
						setRoundTwoArray();
					}
					if(restartUInum == roundThreeUI){
						whichUI = roundThreeStartUI;
						
						fishBowlIsErrorSign = true;
						roundThreeReset();
					}
				
					setTimeout("updateUINum()", 2000);

					initTimer();
			}
			//返回主菜单
			if(e.clientX >= roundWarmingBox.bt2X + canvasLeft &&
				e.clientX < roundWarmingBox.w * 0.5 + roundWarmingBox.bt2X + canvasLeft &&
				e.clientY >= roundWarmingBox.btY + canvasTop &&
				e.clientY < roundWarmingBox.h + roundWarmingBox.y + canvasTop) {
				setTimeout(whichUI = roundDefaultUI, 2000);
			}
		}
	}, false);
var isMouseDown = false;
var fishNum;
canvas.addEventListener("mousedown",
	function(e) {
		if(whichUI == roundThreeUI) {

			fishNum = whichFish(e.clientX - canvasLeft, e.clientY - canvasTop);
			mouseX = e.clientX - mouseXCorrection - canvasLeft;
			mouseY = e.clientY - mouseYCorrection - canvasTop;
			if(fishNum != null) {
				fishArray[fishNum][0] = mouseX;
				fishArray[fishNum][1] = mouseY;
				isMouseDown = true;
				fishArray[fishNum][4] = 1;
			}
		}
	}
)
canvas.addEventListener("mouseup",
	function(e) {
		if(whichUI == roundThreeUI) {
			if(fishNum != null) {
				mouseX = e.clientX - mouseXCorrection - canvasLeft;
				mouseY = e.clientY - mouseYCorrection - canvasTop;
				isMouseDown = false;
				fishArray[fishNum][4] = 0; //脱离抓在手中状态
			}
		}
	}
)
canvas.addEventListener("mousemove",
	function(e) {
		if(whichUI == roundThreeUI) {
			if(isMouseDown) {
				if(fishNum != null) {
					mouseX = e.clientX - mouseXCorrection - canvasLeft;
					mouseY = e.clientY - mouseYCorrection - canvasTop;
					fishArray[fishNum][0] = mouseX;
					fishArray[fishNum][1] = mouseY;

					var fishBowlNum = whichFishBowl(e.clientX - canvasLeft, e.clientY - canvasTop);
					if(fishBowlNum != null) {
						if(fishBowlNum == 1) {
							fishArray[fishNum][3] = 1; //已经被捕捉
							fishArray[fishNum][5] = 1; //放入一号鱼缸

							isMouseDown = false;
						}
						if(fishBowlNum == 2) {
							fishArray[fishNum][3] = 1; //已经被捕捉
							fishArray[fishNum][5] = 2; //放入二号鱼缸

							isMouseDown = false;
						}
						if(fishBowlNum == 3) {
							fishArray[fishNum][3] = 1; //已经被捕捉
							fishArray[fishNum][5] = 3; //放入三号鱼缸

							isMouseDown = false;
						}
					}
				}

			}
		}
	}
)
var defaultBg = new Image();
defaultBg.src = "images/defaultBg.png";
var startOneBtImg = new Image();
startOneBtImg.src = "images/roundStb.png";
var startTwoBtImg = new Image();
startTwoBtImg.src = "images/roundtwoStb.png";
var startThreeBtImg = new Image();
startThreeBtImg.src = "images/roundthrStb.png";
var render = function() {
	//画背景
	if(whichUI == roundDefaultUI) {
		cxt.drawImage(defaultBg, 0, 0, canvas.width, canvas.height);
		//画开始按钮
		if(completeNum == 0) {
			cxt.drawImage(startOneBtImg, start.x, start.y, start.w, start.h);
		}
		if(completeNum == 1) {
			cxt.drawImage(startOneBtImg, start.x, start.y, start.w, start.h);
			cxt.drawImage(startTwoBtImg, startTwo.x, startTwo.y, startTwo.w, startTwo.h);
		}
		if(completeNum == 2) {
			cxt.drawImage(startOneBtImg, start.x, start.y, start.w, start.h);
			cxt.drawImage(startTwoBtImg, startTwo.x, startTwo.y, startTwo.w, startTwo.h);
			cxt.drawImage(startThreeBtImg, startThree.x, startThree.y, startThree.w, startThree.h);
		}
	}
}
defaultBg.onload = function() {
	render();
}
startOneBtImg.onload = function() {
	render();
}
startTwoBtImg.onload = function() {
	render();
}
startThreeBtImg.onload = function() {
	render();
}
var setBoxArray = function() {
	var x = 0;
	var y = 0;
	var w = Box.w;
	var h = Box.h;
	for(var i = 1; i <= 6; i++) {
		if(i == 1) {
			x = canvas.width / 2 - w / 2;
			y = canvas.height * 0.05;
		} else if(i == 2 || i == 3) {
			y = canvas.height * 0.07 + h;
			if(i == 2) {
				x = canvas.width / 2 - w - w / 2;
			} else {
				x = canvas.width / 2 + w / 2;
			}
		} else {
			y = canvas.height * 0.09 + h * 2;
			if(i == 4) {
				x = canvas.width / 2 - w * 2 - w / 2;
			} else if(i == 5) {
				x = canvas.width / 2 - w / 2;
			} else {
				x = canvas.width / 2 + w + w / 2;
			}
		}
		x = toDecimal(x);
		y = toDecimal(y);
		boxArray[i][0] = toDecimal(x);
		boxArray[i][1] = toDecimal(y);

	}
}

function toDecimal(x) {
	var f = parseFloat(x);
	if(isNaN(f)) {
		return;
	}
	f = Math.round(x * 1000) / 1000;
	return f;
}

function round(v, e) {

}
var setBoxSpeed = function() {
	var y = 0;
	var yDefault = 0;
	for(var i = 1; i <= 6; i++) {
		y = boxArray[i][1];
		yDefault = boxArrayDefault[i][1];
		y = toDecimal(y);
		yDefault = toDecimal(yDefault);
		boxSpeed[i] = toDecimal((y - yDefault) / 180);
	}

}
var setBoxArrayDefault = function() {
	var y = -360;
	for(var i = 1; i <= 6; i++) {
		boxArrayDefault[i][1] = y;
		boxArrayDefault[i][0] = boxArray[i][0];
	}
}
var setBottomBoxArray = function() {
	var w = 110;
	var h = 88;
	var x = 110 - 4 + 55;
	var y = canvas.height - h * 2.3;
	for(var i = 1; i <= 12; i++) {
		//x = toDecimal(x);
		//y = toDecimal(y)
		bottomBoxArray[i][0] = x;
		bottomBoxArray[i][1] = y;
		x = x + w * 1.5;
		if(i == 4 || i == 8) {
			y = y - h;
			x = 110 - 4 + 55;
		}

	}
}
setBoxArray();
setBoxArrayDefault();
setBoxSpeed();
setBottomBoxArray();
var whichbox = function(Mx, My) {
	var x = 0;
	var y = 0;
	var w = Box.w;
	var h = Box.h;
	for(var i = 1; i <= 6; i++) {
		x = boxArray[i][0];
		y = boxArray[i][1];
		if(Mx >= x && Mx <= (x + w) && My >= y && My <= (y + h)) {
			return i;
		}
		//return x + " "+ y + " "+(x+w) + " "+(y+h);
	}
	return null;
}
var assignNum = function() {
	rightNum = Math.floor(Math.random() * 5 + 1);
	for(var i = 1; i <= 6; i++) {
		if(i != rightNum) {
			badNum.push(i);
		} else {
			continue;
		}
	}
}
var roundNext = function() { //开始下一回合
	if(roundNum <= 12) {
		roundNum++;
		userSelected = 0;
		setBoxArrayDefault();

		isSelectError = false;
		isSelectRight = false;

		if(roundNum == 13) {
			whichUI = roundOneCompleteUI;
		}
		assignNum();

		roundNextSign = false;
	}
}
var roundReset = function() { //游戏重置
	roundNum = 1;
	userSelected = 0;
	setBoxArrayDefault();

	isSelectError = false;
	isSelectRight = false;

	assignNum();
}
var roundOneBoxBgSign = false;
var roundOneBoxBg = new Image();
roundOneBoxBg.src = "images/roundOneBoxBg.png";
roundOneBoxBg.onload = function() {
	roundOneBgSign = true;
}
var roundOneBoxBgError = new Image();
roundOneBoxBgError.src = "images/roundOneBoxBgError.png";
roundOneBoxBgError.onload = function() {

}
var roundOneBoxBgRight = new Image();
roundOneBoxBgRight.src = "images/roundOneBoxBgRight.png";
roundOneBoxBgRight.onload = function() {

}
var drawRoundOneBox = function() {
	//画六个box
	if(whichUI == roundOneUI) {
		if(roundNum >= 1 && roundNum <= 12) { //1-12回合为第一关
			var x = 0;
			var y = 0;
			var w = Box.w;
			var h = Box.h;
			var t = "友善";
			var badWordCount = 1;
			for(var i = 1; i <= 6; i++) {
				x = boxArrayDefault[i][0];
				y = boxArrayDefault[i][1];

				//正常状态盒子
				if(roundOneBoxBgSign = true) { //此条件现在无效
					cxt.drawImage(roundOneBoxBg, x, y, w, h);
				}
				//正确状态盒子
				if(roundOneBoxBgSign = true && i == rightNum && isSelectRight == true && userSelected == rightNum) {
					cxt.drawImage(roundOneBoxBgRight, x, y, w, h);
				}
				//错误状态盒子
				if(roundOneBoxBgSign = true && i == userSelected && isSelectError == true && userSelected in badNum) {
					cxt.drawImage(roundOneBoxBgError, x, y, w, h);
				}
				if(i == rightNum) {
					t = rightWord[roundNum];
				} else {
					t = badWord[roundNum][badWordCount];
					badWordCount++;
				}
				cxt.beginPath();
				cxt.fillStyle = "#fff";
				cxt.textBaseline = "middle";
				cxt.font = "20px 微软雅黑 bold";
				cxt.fillText(t, x + Box.w / 2 - 20 * (t.length / 2), y + Box.h / 2 - 5);
			}
		}
		if(roundNum >= 2 && roundNum <= 13) { //1-12回合为第一关
			var x = 0;
			var y = 0;
			var w = Box.w;
			var h = Box.h;
			var t = "友善";
			var badWordCount = 1;
			for(var i = 1; i < roundNum; i++) {
				x = bottomBoxArray[i][0];
				y = bottomBoxArray[i][1];

				cxt.drawImage(roundOneBoxBg, x, y, w, h);

				t = rightWord[i];

				cxt.beginPath();
				cxt.fillStyle = "#fff";
				cxt.textBaseline = "middle";
				cxt.font = "20px 微软雅黑 bold";
				cxt.fillText(t, x + Box.w / 2 - 20 * (t.length / 2), y + Box.h / 2 - 5);
			}
		}
		//updateBox()
	}
}
var updateUINum = function() {
	if(whichUI == roundOneStartUI) {
		whichUI = roundOneUI;
		clearTimeout();
	}
	if(whichUI == roundTwoStartUI) {
		whichUI = roundTwoUI;
	}
	if(whichUI == roundThreeStartUI) {
		whichUI = roundThreeUI;
	}
	//setTimeout("updateUINum()", 2000);
}
var drawRoundWarmingInfo = function() { //画提示框
	if(whichUI == roundOneStartUI || whichUI == roundOneCompleteUI || whichUI == roundTwoStartUI || whichUI == roundTwoCompleteUI || whichUI == roundThreeStartUI || whichUI == roundThreeCompleteUI || whichUI == roundEndUI) {
		cxt.beginPath();
		//提示框背景
		cxt.fillStyle = "darkslategrey";
		var x = roundWarmingBox.x;
		var y = roundWarmingBox.y;
		var w = roundWarmingBox.w;
		var h = roundWarmingBox.h;
		var completeSign = false;
		cxt.fillRect(x, y, w, h);
		cxt.lineWidth = 5;
		cxt.strokeStyle = "sienna";
		cxt.strokeRect(x, y, w, h);
		cxt.stroke();
		//提示框文字
		var text = "";
		var text2 = "";
		var text3 = "";
		if(whichUI == roundOneStartUI) {
			text = "第一关";
		}
		if(whichUI == roundOneCompleteUI) {
			text = "恭喜通过第一关！";
			text2 = "进入下一关";
			text3 = "返回主菜单";

			completeSign = true;
		}
		if(whichUI == roundTwoStartUI) {
			text = "第二关";
		}
		if(whichUI == roundTwoCompleteUI) {
			text = "恭喜通过第二关！";
			text2 = "进入下一关";
			text3 = "返回主菜单";
			completeSign = true;
		}
		if(whichUI == roundThreeStartUI) {
			text = "第三关";
		}
		if(whichUI == roundThreeCompleteUI) {
			text = "恭喜通过第三关！";
			text2 = "";
			text3 = "返回主菜单";
			completeSign = true;
		}
		if(whichUI == roundEndUI) {
			text = "通关失败！";
			text2 = "重新开始本关";
			text3 = "返回主菜单";
			completeSign = true;
		}
		if(completeSign) {
			cxt.beginPath();
			cxt.lineWidth = 5;
			cxt.strokeStyle = "sienna";
			cxt.moveTo(roundWarmingBox.btX, roundWarmingBox.btY);
			cxt.lineTo(roundWarmingBox.btX + roundWarmingBox.w, roundWarmingBox.btY);
			cxt.stroke();
			cxt.moveTo(roundWarmingBox.bt2X, roundWarmingBox.bt2Y);
			cxt.lineTo(roundWarmingBox.bt2X, roundWarmingBox.y + h);
			cxt.stroke();
		}
		//console.log(roundWarmingBox.btX, roundWarmingBox.btY, roundWarmingBox.bt2X, roundWarmingBox.bt2Y)
		cxt.fillStyle = "#fff";
		cxt.font = "bold 20px 微软雅黑";
		cxt.fillText(text, x + roundWarmingBox.w * 0.5 - 20 * (text.length / 2), y + 75);
		cxt.fillText(text2, roundWarmingBox.btX + w * 0.25 - 20 * (text2.length / 2), roundWarmingBox.btY + h * 0.12);
		cxt.fillText(text3, roundWarmingBox.bt2X + w * 0.25 - 20 * (text3.length / 2), roundWarmingBox.btY + h * 0.12);
	}
}
var roundOneBgSign = false;
var roundOneBg;
var loadingRoundOneBg = function() {
	roundOneBg = new Image();
	roundOneBg.src = "images/roundOneBg.png";
	roundOneBg.onload = function() {
		roundOneBgSign = true;
	}
}
loadingRoundOneBg();
var roundTwoBgSign = false;
var roundTwoBg;
var loadingRoundTwoBg = function() {
	roundTwoBg = new Image();
	roundTwoBg.src = "images/roundTwoBg-1.png";
	roundTwoBg.onload = function() {
		roundTwoBgSign = true;
	}
}
loadingRoundTwoBg();

var roundThreeBgSign = false;
var roundThreeBg;
var loadingRoundThreeBg = function() {
	roundThreeBg = new Image();
	roundThreeBg.src = "images/roundThreeBg.png";
	roundThreeBg.onload = function() {
		roundThreeBgSign = true;
	}
}
var renderMainUI = function() {
	//提示信息
	drawRoundWarmingInfo();
	if(whichUI == roundOneUI) {
		//第一关背景图
		if(roundOneBgSign) {
			cxt.drawImage(roundOneBg, 0, 0, canvas.width, canvas.height);
		}
		drawRoundOneBox();
	}
	if(whichUI == roundTwoUI) {
		//第二关背景图
		cxt.beginPath();
		cxt.fillStyle = "lemonchiffon";
		cxt.fillRect(0, 0, canvas.width, canvas.height);
		drawRoundTwoBox();
	}
	if(whichUI == roundThreeUI) {
		//第三关背景图
		if(roundTwoBgSign) {
			cxt.drawImage(roundTwoBg, 0, 0, canvas.width, canvas.height);
		}
		drawRoundThreeFish();
	}
	if(whichUI == roundOneUI || whichUI == roundTwoUI || whichUI == roundThreeUI) {
		cxt.beginPath();
		cxt.font = "bold 30px 微软雅黑";
		cxt.fillStyle = "black";
		if(whichUI == roundThreeUI){
			cxt.fillStyle = "white";
		}
		cxt.fillText(Time, canvas.width * 0.01, canvas.height * 0.035);
		cxt.closePath();
	}
}

var fish = {
	x: 0,
	y: 0,
	w: 120,
	h: 75,
	t: ""
}
var fishBowl = {
	x: 0,
	y: 0,
	w: 220,
	h: 180,
	t: ""
}

//第一位：x坐标
//第二位：y坐标
//第三位：鱼上的文字
//第四位：是否已经被捕获     0：未捕获    1：已捕获
//第五位：是否正处于被捕捉状态     0：否    1：是
//第六位：被放入哪个鱼缸     0：未放入    1：国家鱼缸    2：社会鱼缸     3：个人鱼缸
var fishArray = [
	[0, 0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0, 0]
];
var FBOPointArray = [
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0]
];
var FBTwPointArray = [
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0]
];
var FBThPointArray = [
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0],
	[0, 0]
];
var fishBowlOneArray = [0, 0, 0, 0, 0];
var fishBowlTwoArray = [0, 0, 0, 0, 0];
var fishBowlThreeArray = [0, 0, 0, 0, 0];
var fishSpeedArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var fishBowlArray = [
	[0, 0, ""],
	[0, 0, "社会"],
	[0, 0, "个人"],
	[0, 0, "国家"],
];
var fishBowlIsErrorSign = false;
var roundThreeNextSign = false; //
var fishBowlOneCount = 0; //第二关计数
var fishBowlTwoCount = 0;
var fishBowlThreeCount = 0;

var wordExist = function(wordNum) {
	if(wordNum == 0) {
		return true;
	}
	for(var i = 1; i <= 12; i++) {
		if(fishArray[i][2] == wordNum) {
			return true;
		}
	}
	return false;
}
var createFishbowl = function() {
	var x = 50;
	var y = canvas.height * 0.75;
	for(var i = 1; i <= 3; i++) {
		fishBowlArray[i][0] = x;
		fishBowlArray[i][1] = y;
		x = x + fishBowl.w + 100;
		//create fishBowlPoint
		var Px = x - 255;
		var Py = y + 90;
		for(var j = 1; j <= 4; j++) {
			if(i == 1) {
				FBOPointArray[j][0] = Px;
				FBOPointArray[j][1] = Py;
				Px = Px + 30;
			}
			if(i == 2) {
				FBTwPointArray[j][0] = Px;
				FBTwPointArray[j][1] = Py;
				Px = Px + 30;
			}
			if(i == 3) {
				FBThPointArray[j][0] = Px;
				FBThPointArray[j][1] = Py;
				Px = Px + 30;
			}
		}
	}
}
createFishbowl();
var whichFishBowl = function(mouseX, mouseY) {
	var x = 0;
	var y = 0;
	var w = fishBowl.w;
	var h = fishBowl.h;
	for(var i = 1; i <= 3; i++) {
		x = fishBowlArray[i][0];
		y = fishBowlArray[i][1];
		if(mouseX >= x && mouseX <= x + w && mouseY >= y && mouseY <= y + h) {
			return i;
		}
	}
	return null;
}
var setFishArrayDefault = function() {
	var x = 0;
	var y = 0;
	var t = 0;
	var speed = 0;

	var fourth = 0;
	var fifth = 0;
	var sixth = 0;

	for(var i = 1; i <= 12; i++) {
		fishArray[i][0] = x;
		fishArray[i][1] = y;
		fishArray[i][2] = t;
		fishSpeedArray[i] = speed;
		fishArray[i][3] = fourth;
		fishArray[i][4] = fifth;
		fishArray[i][5] = sixth;
	}
}
var createFish = function() {
	var x = 0;
	var y = 0;
	var t = 0;
	var speed = 0;

	//仅用于初始化fishArray第四、五、六位
	var fourth = 0;
	var fifth = 0;
	var sixth = 0;
	
	//用于统计每个鱼缸分配了多少鱼
	var fishBowlOneCount = 1;
	var fishBowlTwoCount = 1;
	var fishBowlThreeCount = 1;
	for(var i = 1; i <= 12; i++) {
		x = -(toDecimal(Math.random() * canvas.width));
		y = toDecimal(Math.random() * canvas.height + canvasTop);
		while(y >= canvas.height * 0.65 + canvasTop) {
			y = toDecimal(Math.random() * canvas.height + canvasTop);
		}
		t = Math.round(Math.random() * 11) + 1;//分配鱼上的文字
		while(wordExist(t)) {
			t = Math.round(Math.random() * 11) + 1;
		}

		speed = Math.round(Math.random() * 1 + 1); //普通鱼速度
		if(t == 4 || t == 6 || t == 12) {
			speed = Math.round(Math.random() * 2 + 2); //特殊鱼速度
		}

		//将各自鱼分配到响应鱼缸
		if(t >= 1 && t <= 4) {
			fishBowlOneArray[fishBowlOneCount] = i;
			fishBowlOneCount++;
		}
		if(t >= 5 && t <= 8) {
			fishBowlTwoArray[fishBowlTwoCount] = i;
			fishBowlTwoCount++;
		}
		if(t >= 9 && t <= 12) {
			fishBowlThreeArray[fishBowlThreeCount] = i;
			fishBowlThreeCount++;
		}

		fishArray[i][0] = x;
		fishArray[i][1] = y;
		fishArray[i][2] = t;
		fishSpeedArray[i] = speed;
		fishArray[i][3] = fourth;
		fishArray[i][4] = fifth;
		fishArray[i][5] = sixth;
	}
}
createFish();
var updateFishArray = function() {
	if(whichUI == roundThreeUI && fishBowlIsErrorSign == false) {
		for(var i = 1; i <= 12; i++) {
			if(fishArray[i][3] == 0 && fishArray[i][4] == 0) {
				var x = fishArray[i][0];
				var speed = fishSpeedArray[i];
				x = x + speed;

				if(x >= canvasLeft + canvas.width + 200) {
					x = -(toDecimal(Math.random() * canvas.width));
					var y = toDecimal(Math.random() * canvas.height + canvasTop);
					while(y >= canvas.height * 0.65 + canvasTop) {
						y = toDecimal(Math.random() * canvas.height + canvasTop);
					}
					fishArray[i][1] = y;
					var t = fishArray[i][2];
					var newSpeed = Math.round(Math.random() * 1 + 1); //普通鱼速度
					if(t == 4 || t == 6 || t == 12) {
						newSpeed = Math.round(Math.random() * 2 + 3); //特殊鱼速度
					}
					fishSpeedArray[i] = newSpeed;
				}
				fishArray[i][0] = x;
			}
		}

	}
}

//检测fishArray的鱼缸是否有错的
var fishBowlIsError = function() {
	if(whichUI == roundThreeUI) {
		var fishNum1 = 0;
		var fishNum2 = 0;
		var fishNum3 = 0;
		for(var i = 1; i <= 4; i++) {
			fishNum1 = fishBowlOneArray[i];
			if(fishArray[fishNum1][5] != 0 && fishArray[fishNum1][5] != 1) {
				fishBowlIsErrorSign = true;
			}
			fishNum2 = fishBowlTwoArray[i];
			if(fishArray[fishNum2][5] != 0 && fishArray[fishNum2][5] != 2) {
				fishBowlIsErrorSign = true;
			}
			fishNum3 = fishBowlThreeArray[i];
			if(fishArray[fishNum3][5] != 0 && fishArray[fishNum3][5] != 3) {
				fishBowlIsErrorSign = true;
			}
		}
	}

}

var roundThreeReset = function() {
	if(fishBowlIsErrorSign == true) {
		setFishArrayDefault();
		createFish();
		fishBowlIsErrorSign = false;
	}
}

var roundThreeNext = function() {
	if(whichUI == roundThreeUI) {
		var fishNum1 = 0;
		var fishNum2 = 0;
		var fishNum3 = 0;
		var Count1 = 0;
		var Count2 = 0;
		var Count3 = 0;
		for(var i = 1; i <= 4; i++) {
			fishNum1 = fishBowlOneArray[i];
			if(fishArray[fishNum1][5] != 0 && fishArray[fishNum1][5] == 1) {
				Count1++;
			}
			fishNum2 = fishBowlTwoArray[i];
			if(fishArray[fishNum2][5] != 0 && fishArray[fishNum2][5] == 2) {
				Count2++;
			}
			fishNum3 = fishBowlThreeArray[i];
			if(fishArray[fishNum3][5] != 0 && fishArray[fishNum3][5] == 3) {
				Count3++;
			}
		}
		fishBowlOneCount = Count1;
		fishBowlTwoCount = Count2;
		fishBowlThreeCount = Count3;
		if(fishBowlOneCount == 4 && fishBowlTwoCount == 4 && fishBowlThreeCount == 4) {
			whichUI = roundThreeCompleteUI;
		}
	}
}

var fishImageArray = [new Image(), new Image(), new Image(), new Image(), new Image(), new Image()];
var loadingFishImage = function() {
	var imagesrc;
	var fishImage;
	for(var i = 1; i <= 5; i++) {
		imagesrc = "images/fish/toRight" + i + ".png"
		fishImage = new Image();
		fishImage.src = imagesrc;
		fishImage.onload = function() {
			fishImageArray[i] = fishImage;
		}
	}

}
//loadingFishImage();

var whichFish = function(mouseX, mouseY) {
	for(var i = 1; i <= 12; i++) {
		var x = fishArray[i][0];
		var y = fishArray[i][1];
		var h = fish.h;
		var w = fish.w;
		if(mouseX >= x && mouseX <= x + w && mouseY >= y && mouseY <= y + h) {
			mouseXCorrection = mouseX - x;
			mouseYCorrection = mouseY - y;
			return i;
		}
	}
	return null;
}

var fishImageSign = false;
var fishImage;
fishImage = new Image();
fishImage.src = "images/fish/toRight1.png";
fishImage.onload = function() {
	fishImageSign = true;
}

var drawRoundThreeFish = function() {
	if(whichUI == roundThreeUI) {
		drawRoundThreeFishBowl();

		for(var i = 1; i <= 12; i++) {

			//var fishImage = fishImageArray[Math.round(Math.random()*4+1)];
			cxt.beginPath();
			if(fishArray[i][3] == 0 && fishArray[i][4] == 0) {
				if(fishImageSign) {
					cxt.drawImage(fishImage, fishArray[i][0], fishArray[i][1], fish.w, fish.h);
				}

				cxt.fillStyle = "aqua";
				cxt.font = "bold 18px 微软雅黑 ";
				cxt.fillText(rightWord[fishArray[i][2]], fishArray[i][0] + 0.35 * fish.w, fishArray[i][1] + 0.1 * fish.h)
			}
			if(fishArray[i][3] == 0 && fishArray[i][4] == 1) {
				if(fishImageSign) {
					cxt.drawImage(fishImage, mouseX, mouseY, fish.w, fish.h);
				}

				cxt.fillStyle = "aqua";
				cxt.font = "bold 18px 微软雅黑 ";
				cxt.fillText(rightWord[fishArray[i][2]], mouseX + 0.35 * fish.w, mouseY + 0.1 * fish.h)
			}
		}

	}
}

var fishBowlImageSign = false;
var fishBowlImage;
var loadingFishBowlImage = function() {
	fishBowlImage = new Image();
	fishBowlImage.src = "images/fishBowl.png";
	fishBowlImage.onload = function() {
		fishBowlImageSign = true;
	}
}
loadingFishBowlImage();
var drawRoundThreeFishBowl = function() {
	if(whichUI == roundThreeUI) {
		for(var i = 1; i <= 3; i++) {
			cxt.beginPath();
			var x = fishBowlArray[i][0];
			var y = fishBowlArray[i][1];
			var h = fishBowl.h;
			var w = fishBowl.w;
			if(fishBowlImageSign) {
				cxt.drawImage(fishBowlImage, x, y, w, h);
			}
			cxt.closePath();
			//鱼缸上绿色圆点
			var Px = 0;
			var Py = 0;
			for(var j = 1; j <= fishBowlOneCount; j++) {
				Px = FBOPointArray[j][0];
				Py = FBOPointArray[j][1];
				cxt.fillStyle = "#0f0";
				cxt.arc(Px, Py, 5, 0, Math.PI * 2, false);
				cxt.fill();
			}
			for(var j = 1; j <= fishBowlTwoCount; j++) {
				Px = FBTwPointArray[j][0];
				Py = FBTwPointArray[j][1];
				cxt.fillStyle = "#0f0";
				cxt.arc(Px, Py, 5, 0, Math.PI * 2, false);
				cxt.fill();
			}
			for(var j = 1; j <= fishBowlThreeCount; j++) {
				Px = FBThPointArray[j][0];
				Py = FBThPointArray[j][1];
				cxt.fillStyle = "#0f0";
				cxt.arc(Px, Py, 5, 0, Math.PI * 2, false);
				cxt.fill();
			}

			//鱼缸上的文字
			var t = fishBowlArray[i][2];
			cxt.fillStyle = "black";
			cxt.font = "bold 24px 微软雅黑 ";
			cxt.fillText(t, x + w / 2 - (24 * t.length / 2), y + h * 0.9);

		}
	}
}

//第一位：x坐标
//第二位：y坐标
//第三位：文字编号    1-12
//第四位：文字是中文还是英文    0为中文  1为英文
//第五位：是否已消除    0为否  1为是
var roundTwoArray = [
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0],
	[0, 0, 0, 0, 0]
];

var roundTwoBox = {
	x: 0,
	y: 0,
	w: 130,
	h: 130
}

var roundTwoSelectOne = 0;
var roundTwoSelectTwo = 0;
var rtSelectRightSign = false;

var setStutsToRight = function() {
	roundTwoArray[roundTwoSelectOne][4] = 1;
	roundTwoArray[roundTwoSelectTwo][4] = 1;
	roundTwoSelectOne = 0;
	roundTwoSelectTwo = 0;
	rtSelectRightSign = false;
}
var rtIsSelectRight = function() {
	if(roundTwoArray[roundTwoSelectOne][2] == roundTwoArray[roundTwoSelectTwo][2]) {
		rtSelectRightSign = true;

		setTimeout("setStutsToRight()", 1000);
	} else {
		roundTwoSelectOne = roundTwoSelectTwo;
		roundTwoSelectTwo = 0;

	}
}

var rtWhichBox = function(Mx, My) {
	var x = 0;
	var y = 0;
	var w = roundTwoBox.w;
	var h = roundTwoBox.h;
	for(var i = 1; i <= 24; i++) {
		x = roundTwoArray[i][0];
		y = roundTwoArray[i][1];
		if(Mx >= x && Mx <= (x + w) && My >= y && My <= (y + h)) {
			return i;
		}
		//return x + " "+ y + " "+(x+w) + " "+(y+h);
	}
	return null;
}

var RTisComplete = function() {
	if(whichUI == roundTwoUI) {
		var count = 0;
		for(var i = 1; i <= 24; i++) {
			if(roundTwoArray[i][4] == 1) {
				count++;
			}
		}
		if(count == 24) {
			whichUI = roundTwoCompleteUI;
		}
	}
}
var RTwordExist = function(wordNum) {
	if(wordNum == 0) {
		return 0;
	}
	var count = 0;
	for(var i = 1; i <= 24; i++) {
		if(roundTwoArray[i][2] == wordNum) {
			count++;
		}
	}
	return count;
}
var getCNorEN = function(wordNum) {
	if(wordNum == 0) {
		return -1;
	}
	for(var i = 1; i <= 24; i++) {
		if(roundTwoArray[i][2] == wordNum) {
			return roundTwoArray[i][3];
		}
	}
	return -1;
}
var setRoundTwoDefault = function() {
	for(var i = 1; i <= roundTwoArray.length - 1; i++) {
		roundTwoArray[i][0] = 0;
		roundTwoArray[i][1] = 0;
		roundTwoArray[i][2] = 0;
		roundTwoArray[i][3] = 0;
		roundTwoArray[i][4] = 0;
	}
	rtSelectRightSign = false;
	roundTwoSelectOne = 0;
	roundTwoSelectTwo = 0;
}
var setRoundTwoArray = function() {
	var x = 75;
	var y = 100;
	var w = roundTwoBox.w;
	var h = roundTwoBox.h;
	var num = 0;
	var CNorEN = 0;
	for(var i = 1; i <= roundTwoArray.length - 1; i++) {
		num = Math.round(Math.random() * 11) + 1;
		while(RTwordExist(num) == 2) {
			num = Math.round(Math.random() * 11) + 1;
		}

		if(RTwordExist(num) == 0) {
			CNorEN = Math.round(Math.random() * 1);
		} else if(RTwordExist(num) == 1) {
			if(getCNorEN(num) == 1) {
				CNorEN = 0;
			} else {
				CNorEN = 1;
			}
		}

		if(i == 7 || i == 13 || i == 19) {
			y = y + h + 2;
			x = 75;
		}
		roundTwoArray[i][0] = x;
		roundTwoArray[i][1] = y;
		roundTwoArray[i][2] = num;
		roundTwoArray[i][3] = CNorEN;
		roundTwoArray[i][4] = 0;
		x = x + w + 2;
	}
}
setRoundTwoArray();

var drawRoundTwoBox = function() {
	if(whichUI == roundTwoUI) {
		for(var i = 1; i <= roundTwoArray.length - 1; i++) {
			var isSelected = roundTwoArray[i][4];
			if(isSelected == 0) {
				cxt.beginPath();
				var x = roundTwoArray[i][0];
				var y = roundTwoArray[i][1];
				var h = roundTwoBox.h;
				var w = roundTwoBox.w;
				var lx = 0;
				var ly = 0;
				var rx = 0;
				var ry = 0;
				if(i == roundTwoSelectOne) {
					cxt.drawImage(roundOneBoxBgRight, x, y, w, h);
				} else if((i == roundTwoSelectOne || i == roundTwoSelectTwo) && rtSelectRightSign == true) {
					cxt.drawImage(roundOneBoxBgRight, x, y, w, h);

					lx = roundTwoArray[roundTwoSelectOne][0] + w / 2;
					ly = roundTwoArray[roundTwoSelectOne][1] + h / 2;
					rx = roundTwoArray[roundTwoSelectTwo][0] + w / 2;
					ry = roundTwoArray[roundTwoSelectTwo][1] + h / 2;
					cxt.lineWidth = "5";
					cxt.strokeStyle = "crimson";
					cxt.moveTo(lx, ly);
					cxt.lineTo(rx, ry);
					cxt.stroke();
				} else if((i == roundTwoSelectOne || i == roundTwoSelectTwo) && rtSelectRightSign == false) {
					cxt.drawImage(roundOneBoxBgError, x, y, w, h);

				} else {
					cxt.drawImage(roundOneBoxBg, x, y, w, h);
				}
				cxt.closePath();

				var textNum = roundTwoArray[i][2];
				var t = "";
				var CNorEN = roundTwoArray[i][3];
				cxt.fillStyle = "black";
				if(CNorEN == 0) {
					t = rightWord[textNum]
					cxt.font = "bold 24px 微软雅黑 ";
					cxt.fillText(t, x + w / 2.0 - (24 * t.length / 2.0), y + h * 0.5);
				}
				if(CNorEN == 1) {
					t = wordEnglishArray[textNum];
					cxt.font = "bold 17px 微软雅黑 ";
					cxt.fillText(t, x + w / 2.0 - (17 * t.length / 4), y + h * 0.5);
				}
			}
		}
		if(rtSelectRightSign == true) {
			lx = roundTwoArray[roundTwoSelectOne][0] + w / 2;
			ly = roundTwoArray[roundTwoSelectOne][1] + h / 2;
			rx = roundTwoArray[roundTwoSelectTwo][0] + w / 2;
			ry = roundTwoArray[roundTwoSelectTwo][1] + h / 2;
			cxt.lineWidth = "5";
			cxt.strokeStyle = "crimson";
			cxt.moveTo(lx, ly);
			cxt.lineTo(rx, ry);
			cxt.stroke();
		}
	}
}

function initTimer() {
	Time = 91;
	clearTimeout(timer);
	var time = function() {
		timer = setTimeout(function() {
			if((whichUI == roundOneUI || whichUI == roundTwoUI || whichUI == roundThreeUI) && Time > 0) {
				Time = Time - 1;
			}
			clearTimeout(timer);
			time();
		}, 1000)
	};
	time();
}
var isGameEnd = function(){
	if(Time == 0 && (whichUI == roundOneUI || whichUI == roundTwoUI || whichUI == roundThreeUI)){
		
		restartUInum = whichUI;//记录重开的关卡
		
		
		whichUI = roundEndUI;
	}
}

var w = window;
requestAnimationFrame = w.requestAnimationFrame || w.webkitRequestAnimationFrame || w.msRequestAnimationFrame || w.mozRequestAnimationFrame;
var main = function() {
	render();
	renderMainUI();
	updateBox();

	fishBowlIsError();
	updateFishArray();
	roundThreeReset();
	roundThreeNext();

	RTisComplete();
	
	isGameEnd();

	requestAnimationFrame(main);
}